package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.domain.UserInfo;
import cn.wolfcode.wolf2w.query.TravelQueryObject;
import cn.wolfcode.wolf2w.redis.service.IRedisService;
import cn.wolfcode.wolf2w.redis.test.RedisByKey;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.util.JsonResult;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/travel")
public class TravelController {

    @Autowired
    private ITravelService travelService;

    @Autowired
    private IRedisService redisService;


    //列表显示
    @RequestMapping("/list")
    public String list(Model model, TravelQueryObject qo){
        Page<Travel> page = travelService.query(qo);
        model.addAttribute("page", page);
        model.addAttribute("qo", qo);
        return "/travel/list";
    }

    //审核处理
    @RequestMapping("/audit")
    @ResponseBody
    public Object audit(String id,int state){
        travelService.audit(id,state);
        return JsonResult.success();
    }

    //查看游记内容处理
    @RequestMapping("/getContentById")
    @ResponseBody
    public Object getContentById(String id){
        String content = travelService.selectOne(id).getContent();
        return JsonResult.success(content);
    }



}
